package com.qf.web.servlet;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author 千锋教育
 * @Company http://www.mobiletrain.org/
 * @Version 1.0
 */
@WebServlet("/test")
public class TestServlet extends HttpServlet{
    //成员变量
    String username ;

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        // 在请求域中存储数据
        req.setAttribute("key", "请求域的数据");

        //重定向
//        resp.sendRedirect("/view");

        //请求转发
        //获取 请求转发对象
        RequestDispatcher rd = req.getRequestDispatcher("/view");
        //转发
        rd.forward(req, resp);
        System.out.println("开发人员也修改了TestServlet.java");
        System.out.println("项目经理修改了TestServlet.java");
        System.out.println("项目经理又修改了TestServlet.java");
        System.out.println("我也收钱了");
        System.out.println("b1: 修改了TestServlet.java");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
